package com.projectx.dao;

import androidx.annotation.Nullable;

import com.projectx.entity.ChatData;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ChatRecordDao {

    /**
     * 返回指定日期之后的对话记录
     * @param username
     * @param contactName
     * @param date 为null时传出所有数据
     * @return
     */
    public List<ChatData> chatRecordAfterData(String username, String contactName, @Nullable Date date){
        List<ChatData> records = LitePal.where("belongToUser = ? and sendUser = ?",username,contactName).find(ChatData.class);
        if (date != null){
            List<ChatData> chatData = new ArrayList<>();
            for (ChatData c:records
            ) {
                if (c.getTime().after(date)) {
                    chatData.add(c);
                }
            }
            return chatData;
        } else {
            return records;
        }

    }
}
